package com.goblin.model.uaa.repository;

import com.goblin.common.response.PageHelper;
import com.goblin.common.response.Paged;
import com.goblin.model.base.BaseRepositoryImpl;
import com.goblin.model.uaa.po.Priv;
import com.goblin.model.uaa.po.QPriv;
import com.querydsl.core.QueryResults;
import com.querydsl.jpa.JPQLQuery;

import javax.persistence.EntityManager;

public class PrivRepositoryImpl extends BaseRepositoryImpl<Priv, Integer>
		implements PrivRepositoryCustom {

	public PrivRepositoryImpl(EntityManager entityManager) {
		super(Priv.class, entityManager);
	}

	@Override
	public Paged<Priv> paged(PageHelper pageable) {
		JPQLQuery<Priv> query = this.jpaQueryFactory.selectFrom(QPriv.priv)
				.where(QPriv.priv.deleteTime.isNull()).orderBy(QPriv.priv.id.desc());
		query = (JPQLQuery<Priv>) getQuerydsl(pageable, query);
		QueryResults<Priv> results = query.fetchResults();
		return new Paged<Priv>(results.getTotal(), results.getResults());
	}
}
